package cn.milai.amtc;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

public class Audio {

	private String code;

	private String resource;

	private Player lastPlayer;

	public Audio(String code, String resource) {
		this.code = code;
		this.resource = resource;
	}

	public void play() {
		try {
			new Player(Audio.class.getResourceAsStream(resource)).play();
		} catch (JavaLayerException e) {
			e.printStackTrace();
		}
	}

	public void play(int frames) {
		try {
			if (lastPlayer == null) {
				lastPlayer = new Player(Audio.class.getResourceAsStream(resource));
			}
			lastPlayer.play(frames);
		} catch (JavaLayerException e) {
			e.printStackTrace();
		}
	}

	public boolean isComplete() {
		return lastPlayer != null && lastPlayer.isComplete();
	}

	public String getCode() {
		return code;
	}

}
